package com.smartcruise.main.selfFragment;

import android.content.Intent;
import android.widget.TextView;

import com.amap.api.maps.offlinemap.OfflineMapActivity;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.smartcruise.MyApplication;
import com.smartcruise.R;
import com.smartcruise.base.BaseTitleFragment;
import com.smartcruise.base.FragmentActivitySimpleImp;
import com.smartcruise.base.TitleBuilder;
import com.smartcruise.main.selfFragment.setting.AboutAppFragment;
import com.smartcruise.main.selfFragment.setting.CleanDataFragment;
import com.smartcruise.main.selfFragment.setting.SelfInfoFragment;
import com.smartcruise.main.selfFragment.setting.VerifyPasswordFragment.VerifyPasswordFragment;
import com.smartcruise.main.selfFragment.setting.languageSetting.LanguageSettingFragment;
import com.smartcruise.report.reportRecord.ReportRecordActivity;
import com.smartcruise.start.flashActivity.FlashActivity;
import com.smartcruise.util.TempleUser;
import com.smartcruise.util.customView.CircleImage;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by FengChaoQun
 * on 2018/1/20 0020
 * 个人页面
 */

public class SelfFragment extends BaseTitleFragment {

    @BindView(R.id.headImage)
    CircleImage headImage;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.phone)
    TextView phone;

    @Override
    protected void init() {
        setEnableRightSlide(false);
        name.setText(TempleUser.getInstance().getUserInfo().getUserName());
        phone.setText(TempleUser.getInstance().getUserInfo().getPhoneNumber());
    }

    @Override
    protected int getContentLayout() {
        return R.layout.fragment_contain_self;
    }

    @Override
    protected TitleBuilder getTitleBuilder() {
        return TitleBuilder.create(false, getString(R.string.mine));
    }

    @OnClick(R.id.selfInfoLay)
    public void onSelfInfoLayClicked() {
        FragmentActivitySimpleImp.start(getActivity(), SelfInfoFragment.class);
    }

    @OnClick(R.id.reportRecord)
    public void onReportRecordClicked() {
        ReportRecordActivity.start(getActivity(), null);
    }

    @OnClick(R.id.commonAddress)
    public void onCommonAddressClicked() {
        showToast(getString(R.string.onDeveloping));
    }

    @OnClick(R.id.cleanData)
    public void onCleanDataClicked() {
        FragmentActivitySimpleImp.start(getActivity(), CleanDataFragment.class);
    }

    @OnClick(R.id.offlineMap)
    public void onOfflineMapClicked() {
//        FragmentActivitySimpleImp.start(getActivity(), OfflineMapFragment.class);
        startActivity(new Intent(getActivity(), OfflineMapActivity.class));
    }

    @OnClick(R.id.languageSet)
    public void onLanguageSetClicked() {
        FragmentActivitySimpleImp.start(getActivity(), LanguageSettingFragment.class);
    }

    @OnClick(R.id.contactService)
    public void onContactServiceClicked() {
        showToast(getString(R.string.onDeveloping));
    }

    @OnClick(R.id.aboutApp)
    public void onAboutAppClicked() {
        FragmentActivitySimpleImp.start(getActivity(), AboutAppFragment.class);
    }

    @OnClick(R.id.modifyPassword)
    public void onModifyPasswordClicked() {
        FragmentActivitySimpleImp.start(getActivity(), VerifyPasswordFragment.class);
    }

    @OnClick(R.id.exitApp)
    public void onExitAppClicked() {
        final NormalDialog normalDialog = new NormalDialog(getActivity());
        normalDialog.content("确定退出登录?")
                .btnText("退出登录", "取消")
                .setOnBtnClickL(new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        exitApp();
                        normalDialog.dismiss();
                    }
                }, new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        normalDialog.dismiss();
                    }
                });
        normalDialog.show();
    }

    private void exitApp() {
        MyApplication.getInstance().exitApp();
        startActivity(new Intent(getActivity(), FlashActivity.class));
    }

}
